package com.lcz.authority.common.exception;

import com.lcz.authority.common.exception.base.BaseException;
import lombok.Getter;

/**
 * @author lcz
 * @desc 业务异常
 * @mail lcz_0130@163.com
 * @date 2024/05/06
 */
public final class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    @Getter
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 空构造方法，避免反序列化问题
     */
    public ServiceException() {
    }

    public ServiceException(String message) {
        this.message = message;
    }

    public ServiceException(BaseException baseException) {
        this.message = baseException.getDefaultMessage();
        this.code = baseException.getCode();

    }

    public ServiceException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public ServiceException setMessage(String message) {
        this.message = message;
        return this;
    }

}
